package cn.gok.demo.base.service;

import cn.gok.demo.base.dao.BaseMapper;
import cn.gok.demo.base.entity.BaseEntity;
import cn.gok.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @Author: zhengyx
 * @Date: 2022/7/26 11:39
 * @Version 1.0
 */
public class BaseService<T extends BaseEntity,M extends BaseMapper<T>>{
    @Autowired
    M mapper;
    public List<T> list() {
        return mapper.list();
    }

    public int save(T t){
        t.setUpdateTime(new Date());
        t.setCreateTime(new Date());
        return mapper.save(t);
    }

    public int delete(Integer id){
        return mapper.delete(id);
    }

    public int update(T t){
        t.setUpdateTime(new Date());
        return mapper.update(t);
    }

    public T findById(Integer id){
        return mapper.findById(id);
    }

}
